package charpter11.lynx;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


public class Ten {
	public static void main (String[] args){
		List<Rodent> rodents = new ArrayList<Rodent>();
		rodents.add(new Mouse());
		rodents.add(new Hamster());
		rodents.add(new Gerbil());
		
		Iterator<Rodent> it = rodents.iterator();
		while(it.hasNext()){
			it.next().bite();
		}
	}
}
class Rodent {
	static long counter;
	static{
		counter = 0;
	}
	public Rodent() {
		System.out.println("Rodent initialized.");
		counter++;
	}
	void bite(){
		System.out.println("Rodent bite");
	}
	void dispose() throws Throwable{
		counter--;
		if (counter == 0){
			super.finalize();
		}
	}
}

class Mouse extends Rodent{
	public Mouse() {
		System.out.println("Mouse initialized.");
	}
	@Override
	void bite(){
		System.out.println("Mouse bite");
	}
}

class Gerbil extends Rodent{
	public Gerbil() {
		System.out.println("Gerbil initialized.");
	}
	@Override
	void bite(){
		System.out.println("Gerbil bite");
	}
}

class Hamster extends Rodent{
	public Hamster() {
		System.out.println("Hamster initialized.");
	}
	@Override
	void bite(){
		System.out.println("Hamster bite");
	}
}